/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package object;

/**
 *
 * @author dheath
 */
public class Edge implements Comparable
{
    private float Ymin;
    private float Ymax;
    private float X;
    private float mX;
    private float Z;
    private float mZ;
    
    private boolean horizontal;
    
    private float nX;
    private float nY;
    private float nZ;
    private float mnX;
    private float mnY;
    private float mnZ;
    
    private float wX;
    private float wY;
    private float wZ;
    private float mwX;
    private float mwY;
    private float mwZ;
    
    public Edge(Point start, Point end, Point wS, Point wE)
    {
        horizontal = false;
        
        
        if(start.getY() < end.getY())
        {
            Z = start.getZ();
            nX = start.getNormal().getX();
            nY = start.getNormal().getY();
            nZ = start.getNormal().getZ();
            
            wX = wS.getX();
            wY = wS.getY();
            wZ = wS.getZ();
        }
        else
        {
            Z = end.getZ();
            nX = end.getNormal().getX();
            nY = end.getNormal().getY();
            nZ = end.getNormal().getZ();
            
            wX = wE.getX();
            wY = wE.getY();
            wZ = wE.getZ();
        }
        
        if(start.getY() < end.getY())
        {
            Ymin = start.getY();
            X = start.getX();
            Ymax = end.getY();
            
            mX = (end.getX() - start.getX())/(end.getY() - start.getY());
            mZ = (end.getZ() - start.getZ())/(end.getY() - start.getY());
            
            mnZ = (end.getNormal().getZ() - start.getNormal().getZ())/(end.getY() - start.getY());
            mnX = (end.getNormal().getX() - start.getNormal().getX())/(end.getY() - start.getY());
            mnY = (end.getNormal().getY() - start.getNormal().getY())/(end.getY() - start.getY());
            
            mwZ = (wE.getZ() - wS.getZ())/(end.getY() - start.getY());
            mwX = (wE.getX() - wS.getX())/(end.getY() - start.getY());
            mwY = (wE.getY() - wS.getY())/(end.getY() - start.getY());
            //System.out.println(mX);
        }
        else if(end.getY() < start.getY())
        {
            Ymin = end.getY();
            X = end.getX();
            Ymax = start.getY();
            
            mX = (start.getX() - end.getX())/(start.getY() - end.getY());
            mZ = (start.getZ() - end.getZ())/(start.getY() - end.getY());
            
            mnZ = (start.getNormal().getZ() - end.getNormal().getZ())/(start.getY() - end.getY());
            mnX = (start.getNormal().getX() - end.getNormal().getX())/(start.getY() - end.getY());
            mnY = (start.getNormal().getY() - end.getNormal().getY())/(start.getY() - end.getY());
            
            mwZ = (wS.getZ() - wE.getZ())/(end.getY() - start.getY());
            mwX = (wS.getX() - wE.getX())/(end.getY() - start.getY());
            mwY = (wS.getY() - wE.getY())/(end.getY() - start.getY());
            //System.out.print(mX);
        }
        else
        {
            horizontal = true;
        }
        
    }
    
    public int compareTo(Object o)
    {
        if(!(o instanceof Edge))
        {
            return -1;
        }
        
        Edge e = (Edge)o;
        
        if(getX() < e.getX())
        {
            return -1;
        }
        else if(getX() > e.getX())
        {
            return 1;
        }
        else
        {
            return 0;
        }
        
    }
    
    public void normalizeNormals()
    {
        float len = length();
        
        nX = nX/len;
        nY = nY/len;
        nZ = nZ/len;
    }
    public float length()
    {
        return (float)Math.sqrt(nX*nX+nY*nY+nZ*nZ);
    }
    public float horizontalSlope(Edge edge1, Edge edge2)
    {
        return ((edge2.getZ() - edge1.getZ())/(edge2.getX() - edge1.getX()));
    }
    
    public float getWxSLope(Edge e1, Edge e2)
    {
        return ((e2.getWX() - e1.getWX())/(e2.getX() - e1.getX()));
    }
    public float getWySLope(Edge e1, Edge e2)
    {
        return ((e2.getWY() - e1.getWY())/(e2.getX() - e1.getX()));
    }
    public float getWzSLope(Edge e1, Edge e2)
    {
        return ((e2.getWZ() - e1.getWZ())/(e2.getX() - e1.getX()));
    }
    
    public float getNxSLope(Edge e1, Edge e2)
    {
        return ((e2.getNX() - e1.getNX())/(e2.getX() - e1.getX()));
    }
    public float getNySLope(Edge e1, Edge e2)
    {
        return ((e2.getNY() - e1.getNY())/(e2.getX() - e1.getX()));
    }
    public float getNzSLope(Edge e1, Edge e2)
    {
        return ((e2.getNZ() - e1.getNZ())/(e2.getX() - e1.getX()));
    }
    public void incrementNormal()
    {
        nZ += mnZ;
        nY += mnY;
        nZ += mnZ;
    }
    public void incrementWorld()
    {
        wZ += mwZ;
        wY += mwY;
        wZ += mwZ;
    }
    public void incrementCurrentZ()
    {
        Z += mZ;
    }
    public void incrementCurrentX()
    {
        X += mX;
    }
    
    public float getYmin()
    {
        return Ymin;
    }

    public void setYmin(float Ymin)
    {
        this.Ymin = Ymin;
    }

    public float getYmax()
    {
        return Ymax;
    }

    public void setYmax(float Ymax)
    {
        this.Ymax = Ymax;
    }
    
    public float getNX()
    {
        return nX;
    }
    public float getNY()
    {
        return nY;
    }
    public float getNZ()
    {
        return nZ;
    }
    public float getMX()
    {
        return mX;
    }

    public void setMX(float mX)
    {
        this.mX = mX;
    }

    public float getX()
    {
        return X;
    }

    public void setX(float X)
    {
        this.X = X;
    }

    public boolean isHorizontal()
    {
        return horizontal;
    }

    public void setHorizontal(boolean isHorizontal)
    {
        this.horizontal = isHorizontal;
    }

    public float getZ()
    {
        return Z;
    }

    public void setZ(float Z)
    {
        this.Z = Z;
    }

    public float getMZ()
    {
        return mZ;
    }

    public void setMZ(float mZ)
    {
        this.mZ = mZ;
    }

    public float getWX()
    {
        return wX;
    }

    public void setWX(float wX)
    {
        this.wX = wX;
    }

    public float getWY()
    {
        return wY;
    }

    public void setWY(float wY)
    {
        this.wY = wY;
    }

    public float getWZ()
    {
        return wZ;
    }

    public void setWZ(float wZ)
    {
        this.wZ = wZ;
    }

    public float getMwX()
    {
        return mwX;
    }

    public void setMwX(float mwX)
    {
        this.mwX = mwX;
    }

    public float getMwY()
    {
        return mwY;
    }

    public void setMwY(float mwY)
    {
        this.mwY = mwY;
    }

    public float getMwZ()
    {
        return mwZ;
    }

    public void setMwZ(float mwZ)
    {
        this.mwZ = mwZ;
    }
    
    
}
